package com.nari.ncps.screen.service.impl.coal;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nari.ncps.screen.entity.coal.CoalSafetyenvRestoration;
import com.nari.ncps.screen.mapper.coal.CoalSafetyenvRestorationMapper;
import com.nari.ncps.screen.service.coal.CoalSafetyenvRestorationService;
import com.nari.ncps.screen.vo.coal.CoalEcoRestorationVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 安全环保生态修复面积表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class CoalSafetyenvRestorationServiceImpl extends ServiceImpl<CoalSafetyenvRestorationMapper, CoalSafetyenvRestoration> implements CoalSafetyenvRestorationService {

    @Override
    public List<CoalEcoRestorationVO> getEcoRestoration(Integer year) {
        // 如果year为null，默认使用当前年份
        if (year == null) {
            year = java.time.LocalDate.now().getYear();
        }
        
        // 查询指定年份的生态修复数据
        QueryWrapper<CoalSafetyenvRestoration> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("year", year);
        queryWrapper.orderByAsc("org_code");
        
        List<CoalSafetyenvRestoration> restorationList = this.list(queryWrapper);
        
        // 转换为VO对象
        return restorationList.stream().map(entity -> {
            CoalEcoRestorationVO vo = new CoalEcoRestorationVO();
            vo.setUnitCode(entity.getOrgCode());
            vo.setUnitName(entity.getOrgName());
            vo.setRestorationVolume(entity.getRestorationVolume());
            return vo;
        }).collect(Collectors.toList());
    }

}
